package com.ruoyi.sales.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.sales.mapper.ZcWorkshopMapper;
import com.ruoyi.sales.domain.ZcWorkshop;
import com.ruoyi.sales.service.IZcWorkshopService;

/**
 * 车间信息Service业务层处理
 * 
 * @author woo
 * @date 2024-03-26
 */
@Service
public class ZcWorkshopServiceImpl implements IZcWorkshopService 
{
    @Autowired
    private ZcWorkshopMapper zcWorkshopMapper;

    /**
     * 查询车间信息
     * 
     * @param workshopId 车间信息主键
     * @return 车间信息
     */
    @Override
    public ZcWorkshop selectZcWorkshopByWorkshopId(Long workshopId)
    {
        return zcWorkshopMapper.selectZcWorkshopByWorkshopId(workshopId);
    }

    /**
     * 查询车间信息列表
     * 
     * @param zcWorkshop 车间信息
     * @return 车间信息
     */
    @Override
    public List<ZcWorkshop> selectZcWorkshopList(ZcWorkshop zcWorkshop)
    {
        return zcWorkshopMapper.selectZcWorkshopList(zcWorkshop);
    }

    /**
     * 新增车间信息
     * 
     * @param zcWorkshop 车间信息
     * @return 结果
     */
    @Override
    public int insertZcWorkshop(ZcWorkshop zcWorkshop)
    {
        zcWorkshop.setCreateTime(DateUtils.getNowDate());
        zcWorkshop.setDel(0);

        List<ZcWorkshop> list = zcWorkshopMapper.selectAll();
        for (ZcWorkshop workshop : list) {
            if (zcWorkshop.getName().equals(workshop.getName()) && zcWorkshop.getType().equals(workshop.getType())){
                return 0;
            }
        }

        return zcWorkshopMapper.insertZcWorkshop(zcWorkshop);
    }

    /**
     * 修改车间信息
     * 
     * @param zcWorkshop 车间信息
     * @return 结果
     */
    @Override
    public int updateZcWorkshop(ZcWorkshop zcWorkshop)
    {
        zcWorkshop.setUpdateTime(DateUtils.getNowDate());
        return zcWorkshopMapper.updateZcWorkshop(zcWorkshop);
    }

    /**
     * 批量删除车间信息
     * 
     * @param workshopIds 需要删除的车间信息主键
     * @return 结果
     */
    @Override
    public int deleteZcWorkshopByWorkshopIds(Long[] workshopIds)
    {
        return zcWorkshopMapper.deleteZcWorkshopByWorkshopIds(workshopIds);
    }

    /**
     * 删除车间信息信息
     * 
     * @param workshopId 车间信息主键
     * @return 结果
     */
    @Override
    public int deleteZcWorkshopByWorkshopId(Long workshopId)
    {
        return zcWorkshopMapper.deleteZcWorkshopByWorkshopId(workshopId);
    }

    @Override
    public int updateCodecStatus(ZcWorkshop workshop) {
        return zcWorkshopMapper.updateCode(workshop);
    }

    @Override
    public List<ZcWorkshop> selectShopAll() {

        return zcWorkshopMapper.selectAll();
    }

    @Override
    public List<Long> selectZcWorkshopListByUserId(Long userId) {
        return zcWorkshopMapper.selectZcWorkshopListByUserId(userId);
    }

//    @Override
//    public int checkWorkshopExists(ZcWorkshop workshop) {
////        List<ZcWorkshop> arrayList = new ArrayList<>();
////        ZcWorkshop zw = new ZcWorkshop();
//        List<ZcWorkshop> list = zcWorkshopMapper.selectAll();
//        for (ZcWorkshop zcWorkshop : list) {
//            // 前大于后 = 1，前等于后 = 0，前小于后 = -1
//            if (!(zcWorkshop.getName().equals(workshop.getName())&&zcWorkshop.getType().equals(workshop.getType()))){
//
//            }
//        }
//        return 0;
//    }
}
